package com.he.simplefactorymodel.factory;

import com.he.simplefactorymodel.product.concreteproduct.AddOpt;
import com.he.simplefactorymodel.product.concreteproduct.DivOpt;
import com.he.simplefactorymodel.product.concreteproduct.MulOpt;
import com.he.simplefactorymodel.product.concreteproduct.SubOpt;
import com.he.simplefactorymodel.product.Operator;

import java.math.BigDecimal;

/**
 *
 * 简单工厂方法，用于实现简单的数据计算操作，跟据泛型搭配，灵活运用
 */
public class SimpleFactory {
    public static <T extends  Operator<BigDecimal>> Operator<BigDecimal> getOpt(Class<T> tClass) throws AssertionError {
        if (AddOpt.class == tClass) {
            return new AddOpt();
        } else if (MulOpt.class.equals(tClass)) {
            return new MulOpt();
        }else if (SubOpt.class.equals(tClass)) {
            return new SubOpt();
        }else if (DivOpt.class.equals(tClass)) {
            return new DivOpt();
        }
        throw new AssertionError("请传入标准的运算操作符");
    }


}
